/**
 * 
 */
package negocio.Motor;

import integracion.Factoria.*;
import integracion.Motor.DAOMotor;
import integracion.Vehiculo.DAOVehiculo;

public class SAMotorImp implements SAMotor {
	

	@Override
	public boolean crearMotor(TransferMotor t) {	

		 FactoriaDAO FacTdao = FactoriaDAO.getInstancia();
		 DAOMotor daoMotor = FacTdao.newDAOMotor();
		 if(daoMotor.creable(t))
			 return daoMotor.create(t);
		 return false;
	}

	@Override
	public boolean eliminarMotor(TransferMotor t) {
		
		FactoriaDAO FactDao = FactoriaDAO.getInstancia();
		DAOMotor daoMotor = FactDao.newDAOMotor();			
		DAOVehiculo daoVehiculo = FactDao.newDAOVehiculo();	
	
		if(daoMotor.deletable(t) && !daoVehiculo.containsMotor(t.getId()))
			return daoMotor.delete(t);
		return false;
	}

	@Override
	public TransferMotor buscarMotor(int id) {
		
		FactoriaDAO FactDao = FactoriaDAO.getInstancia();
		DAOMotor daoMotor = FactDao.newDAOMotor();
		if(daoMotor.searchable(id))
			return daoMotor.readById(id);
		return null;
	}

	@Override
	public boolean actualizarMotor(TransferMotor t) { 		
		FactoriaDAO FactDao = FactoriaDAO.getInstancia();
		DAOMotor daoMotor = FactDao.newDAOMotor();
		if(daoMotor.updatable(t))
			return daoMotor.update(t);
		return false;
	}
	
	
	
}